class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        if len(s) != len(t):
            return False
        def getDic(s):
            dic = {x:0 for x in set(s)}
            for i in s:
                dic[i] = dic[i] + 1
            return dic
        sdic = getDic(s)
        tdic = getDic(t)
        for key in sdic:
            sval = sdic[key]
            if key in tdic:
                tval = tdic.pop(key)
                if sval!= tval:
                    return False
            else:
                return False
        return len(tdic) == 0




if __name__ == '__main__':
    so = Solution()
    s = "rat"
    t = "car"
    r = so.isAnagram(s, t)
    print(r)
